<?php

namespace app\admin\service;

use app\common\Error;
use app\model\User;
use app\model\Admin;
use app\model\Partner;

class PartnerService
{
    private $model;


    private $adminModel;
    private $PartnerModel;


    public function __construct(User $model , Admin $adminModel, Partner $PartnerModel)
    {
        $this->model = $model;


        $this->adminModel = $adminModel;
   

        $this->PartnerModel = $PartnerModel;
    }



    /**
     * 获取列表
     */
    public function getPartnerList($params)
    {
        $page = $params['page'] ?? 1;
        $limit = $params['limit'] ?? 10;
        $where = [];
        $data = $this->PartnerModel->getPagingDataByWhere($where, $page, $limit, '*');
        $partner_type = config('app.partner_type', 'json');
        $typeResult = array_column($partner_type, 'name', 'id');
        foreach ($data['data'] as $key => $item) {
            $data['data'][$key]['type_name'] = empty($typeResult[$item['type']]) ? '' : $typeResult[$item['type']];
        }
        return $data;
    }

    // 获取详情
    public function getPartnerDetail($id)
    {
        $data = $this->PartnerModel->getInfoById($id, '*');
        return $data;
    }

    // 添加/修改
    public function editPartner($params)
    {
        if (empty($params['id'])) {
            $params['created_at'] = time();

        } else {

        }

        $id = $this->PartnerModel->edit($params);

        if (!$id) {
            return false;
        }

        return true;
    }




}